import requests
import json
import time

# API URL
api_url = "https://iot-api.heclouds.com/thingmodel/query-device-property"
authorizationKey ="version=2022-05-01&res=userid%2F378829&et=1745595703&method=sha1&sign=MbkKStlGzWOmL1%2BbgO3bkDcCYYQ%3D"
# 请求头
headers = {
    "User-Agent": "My Python Script",
    "authorization": authorizationKey,
}

# 发送数据
data = {
            "device_name": "d1",
            "product_id": "zy1NTZomN9",
}
def get_data():
    response = requests.get(api_url, headers=headers, params=data)
    if response.status_code == 200:
     with open("response_data.json", "w") as file:
        json.dump(response.json(), file, indent=4)
    print("数据已保存到 response_data.json 文件中")
    data1 = response.json()
    for item in data1['data']:
        if item.get('identifier') == 'test':
            return item.get('value')
    else:
        print("请求失败，状态码:", response.status_code)


while True:
    value = get_data()
    if value:
        print(f"Value for identifier 'test': {value}")
    else:
        print("Value not found for identifier 'test'")

    time.sleep(5)  # 暂停 5 秒后再次执行请求





























# for i in range():
#
#
#     time.sleep(3)